package com.lzy.cloud.common.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.common.dtos.ParamDto;
import com.lzy.cloud.common.entity.Param;
import com.lzy.cloud.common.mapper.ParamMapperExt;
import com.lzy.cloud.common.service.ParamService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ParamServiceImpl implements ParamService {

    @Autowired
    private ParamMapperExt paramMapperExt;


    @Override
    public Boolean addParam(ParamDto paramDto) {
        return paramMapperExt.insertSelective(DozerUtils.map(paramDto,Param.class)) > 0;
    }

    @Override
    public ParamDto selectByKey(String paramKey) {
        return DozerUtils.map(paramMapperExt.selectByKey(paramKey), ParamDto.class);
    }

    @Override
    public Boolean update(ParamDto paramDto) {
        return paramMapperExt.updateByPrimaryKeySelective(DozerUtils.map(paramDto,Param.class)) > 0;
    }

    @Override
    public Boolean deleteParam(String id) {
        String[] ids = id.split(",");
        for (String idx:ids) {
            paramMapperExt.deleteByPrimaryKey(Long.valueOf(idx));
        }
        return true;
    }

    @Override
    public PageInfo selectParamList(Pager pager, ParamDto paramDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<ParamDto> permissionDtoList = paramMapperExt.selectList(paramDto);
        return new PageInfo(permissionDtoList);
    }
}

